﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Algorithms
{
    public static class CustomMath
    {
        public static int ToRange(uint number, int max)
        {
            return ToRange(number, 0, max);
        }

        public static int ToRange(uint number, int min, int max)
        {
            if (max < min)
                throw new ArgumentOutOfRangeException("Max can't be bigger then min");

            int width = max - min;
            if (width == 0)
            {
                return min;
            }
            else if (width == 1)
            {
                // if number dividable by 2
                return (number % 2) == 0 ? 0 : 1;
            }
            else
            {
                return min + (int)(number % width);
            }
        }
    }
}
